package com.yuncheng.spcyApi.selectXzxkApi.api;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yuncheng.spcyApi.selectXzxkApi.vo.*;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuncheng.spcyApi.alog.annotation.Log;
import com.yuncheng.spcyApi.config.SpcyMinioUtils;
import com.yuncheng.spcyApi.constant.common.SpcyConstant;
import com.yuncheng.spcyApi.constant.sys.SysConfigConstant;
import com.yuncheng.spcyApi.entity.SpcySqsxBasic;
import com.yuncheng.exception.BusinessException;
import com.yuncheng.spcyApi.mapper.XzXkMapper;
import com.yuncheng.spcyApi.selectXzxkApi.constant.XzXkConstant;
import com.yuncheng.spcyApi.selectXzxkApi.constant.XzXkEnumConstant;
import com.yuncheng.spcyApi.selectXzxkApi.service.*;
import com.yuncheng.spcyApi.service.ISpcySqsxBaiscService;
import com.yuncheng.spcyApi.service.ISysConfigService;
import com.yuncheng.spcyApi.utils.GetCurrentUserUtils;
import com.yuncheng.spcyApi.utils.LocalFileUploadUtils;
import com.yuncheng.spcyApi.utils.MapUtils;
import com.yuncheng.vo.HttpResult;
import com.yuncheng.spcyApi.vo.common.HttpResultVo;
import com.yuncheng.spcyApi.vo.common.PageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;
import utils.DateConversionUtils;
import utils.PdfUtils;
import utils.Util;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;

@Api(tags = "审评查验-行政审批接口")
@RestController
@RequestMapping("/api/spzx-spcy/xzxkApi")
public class SelectXzxkApi {
    private static final Logger log = LoggerFactory.getLogger(SelectXzxkApi.class);

    @Resource
    private XzXkMapper xzXkMapper;

    @Resource
    private YpscXzxkService ypscXzxkService;

    @Resource
    private YlqxXzxkService ylqxXzxkService;

    @Resource
    private YpzcXzxkService ypzcXzxkService;

    @Resource
    private YpltXzxkService ypltXzxkService;

    @Resource
    private HzpXzxkService hzpXzxkService;

    @Resource
    private ISpcySqsxBaiscService spcySqsxBaiscService;

    @Resource
    private SpcyMinioUtils spcyMinioUtils;

    @Resource
    private LocalFileUploadUtils localFileUploadUtils;

    @Resource
    private XzspJkApi xzspJkApi;

    @Autowired
    @Qualifier("asyncNormalTask")
    private Executor executor;

    @Resource
    private ISysConfigService sysConfigService;

    /** 是否开启同步政务服务事项 */
    private boolean verifyEnableSyncSqsx(){
        String code = Optional.ofNullable(sysConfigService.getSysConfigByCode(SysConfigConstant.SYNC_ZWFWXT_SQSX)).orElseGet(()->"0");
        if (code.equals("0")){
            return false;
        }else {
            return true;
        }
    }

    @Log(title = "根据证件号码Or姓名-获取对应人员的企业兼职情况")
    @ApiOperation(value = "根据证件号码Or姓名-获取对应人员的企业兼职情况")
    @GetMapping(value = "queryQyRyJzqkByZjhm")
    public HttpResult queryQyRyJzqkByZjhm(@RequestParam(value = "zjhm",defaultValue = "")String zjhm,
                                          @RequestParam(value = "ryfl",defaultValue = "")String ryfl,
                                          @RequestParam(value = "xm",defaultValue = "")String xm){

        QyRyJzqkVo query = new QyRyJzqkVo();
        if (StringUtils.isNotBlank(ryfl)) {
            query.setRyfl(ryfl);
        }

        List<QyRyJzqkVo> list = new ArrayList<>();
        if (StringUtils.isNotBlank(zjhm) && StringUtils.isNotBlank(xm)) {
            query.setCxzjhm(zjhm);
            query.setCxxm(xm);
            query.setCxzjhmhxm("是");

        }else {
            if (StringUtils.isNotBlank(zjhm)) {
                query.setZjhm(zjhm);

            } else if (StringUtils.isNotBlank(xm)) {
                query.setXm(xm);
            }
        }

//        list = xzXkMapper.selecyQyRyJzqkTotalList(query);

        return HttpResultVo.HttpResultList(list);
    }

    @Log(title = "获取对应人员的企业兼职情况总库")
    @ApiOperation(value = "获取对应人员的企业兼职情况总库")
    @GetMapping(value = "queryQyRyJzqkTotal")
    public HttpResult queryQyRyJzqkTotal(QyRyJzqkVo query, PageVo pageVo){

        /*Page<QyRyJzqkVo> page = new Page<>(pageVo.getPageNo(),pageVo.getPageSize());
        Page<QyRyJzqkVo> pageList = xzXkMapper.selecyQyRyJzqkTotalPageList(page, query);*/
        return HttpResult.ok();
    }

    @Log(title = "政务申请事项-详情信息")
    @ApiOperation(value = "政务申请事项-详情信息")
    @GetMapping(value = "querySqsxJbxxWithSqlx")
    public HttpResult<?> querySqsxJbxxWithSqlx(@RequestParam(value = "sqsxid",defaultValue = "") String sqsxid){
        Map resultMap = new HashMap();
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("申请事项主要参数丢失，请联系管理员");
        }

        /*String fywflcode = "";
        SpcySqsxBasic sqsx = spcySqsxBaiscService.selectSqsxById(sqsxid);
        if (sqsx != null){
            sqsxid = sqsx.getFsxsqjbxxid();
            fywflcode = sqsx.getFywflcode();
        }*/

        /*String sqsxbm = "";

        // 申请事项
        String finalSqsxid = sqsxid;
        String finalFywflcode = fywflcode;*/

        /** 申请材料-附件信息 */
        /*XzspSqsxVo sqsxMap = xzXkMapper.selectSqsx(finalSqsxid);
        if (sqsxMap == null){
            return HttpResult.ok(resultMap);
        }*/
//        resultMap.put("sqsx", sqsxMap);

        /*sqsxbm = sqsxMap.getSqsxbm();

        String finalSqsxbm = sqsxbm;

        *//** 申请材料-附件信息 *//*
        CompletableFuture<String> futurefjxxList = CompletableFuture.supplyAsync(() -> {
            String zdrq = "";
            if (StringUtils.isBlank(zdrq) && sqsx.getFslsj() != null){
                zdrq = DateConversionUtils.DateToDays(sqsx.getFslsj());
            }else {
                zdrq = DateConversionUtils.DateToDays(new Date());
            }

            // 申请材料-附件信息
    //        List<Map<String, Object>> fjxxList = xzXkMapper.selectFjxx(sqsxid, XzXkConstant.FJXX_FJLX_QYTJCL);
            List<Map<String, Object>> fjxxList = xzXkMapper.selectFjxxSqsjWithDySlsj(finalSqsxid, XzXkConstant.FJXX_FJLX_QYTJCL,null,null,zdrq);
            JSONArray fjxxArray = MapUtils.listMapToJson(fjxxList);
            resultMap.put("fjxxList", fjxxArray);

            return "1";
        }, executor);

        *//** 办理流程历史记录 *//*
        CompletableFuture<String> futureLclsjl = CompletableFuture.supplyAsync(() -> {
            // 办理流程历史记录
            resultMap.putAll(this.lcLsJl(finalSqsxid));

            return "1";
        }, executor);

        *//** 查询详情 *//*
        CompletableFuture<String> futureInfo = CompletableFuture.supplyAsync(() -> {
        // 药品生产
        if (finalFywflcode.equals(SpcyConstant.YWFL_CODE_YPSC)) {

            resultMap.putAll(this.sqsxFormInYpsc(finalSqsxid, finalSqsxbm,sqsxMap));

        }
        else if (finalFywflcode.equals(SpcyConstant.YWFL_CODE_YLQX)){
            // 医疗器械
            resultMap.putAll(this.sqsxFormInYlqx(finalSqsxid, finalSqsxbm,sqsxMap));

        }
        else if (finalFywflcode.equals(SpcyConstant.YWFL_CODE_YPZC)){
            // 药品注册

            resultMap.putAll(this.sqsxFormInYpzc(finalSqsxid, finalSqsxbm));

        }
        else if (finalFywflcode.equals(SpcyConstant.YWFL_CODE_YPJY)){
            // 药品流通

            resultMap.putAll(this.sqsxFormInYplt(finalSqsxid, finalSqsxbm));

        }
        else if (finalFywflcode.equals(SpcyConstant.YWFL_CODE_HZP)){
            // 化妆品
            resultMap.putAll(this.sqsxFormInHzp(finalSqsxid, finalSqsxbm));
        }
        else {

            // 企业信息
            List<XzspSqsxXdrxxVo> qyList = xzXkMapper.selectQyxxList(finalSqsxid);

            if (CollectionUtils.isNotEmpty(qyList)) {
                resultMap.put("qyxx", qyList.get(0));
            } else {
                resultMap.put("qyxx", new JSONObject());
            }

            // 企业人员-主要人员 / 其他人员
            resultMap.putAll(ypscXzxkService.qyryListMap(finalSqsxid));
        }

            return "1";
        }, executor);

        *//** 等待所有结果执行完成 *//*
        try {
            CompletableFuture.allOf(futurefjxxList, futureLclsjl, futureInfo).get();
        } catch (InterruptedException e) {
            log.error("[InterruptedException]申请事项-详情信息: {}", e.getMessage());
        } catch (ExecutionException e) {
            log.error("[InterruptedException]申请事项-详情信息: {}", e.getMessage());
        }*/

        return HttpResult.ok(resultMap);
    }

    @Log(title = "查询政务系统-流转历史记录")
    @ApiOperation(value = "查询政务系统-流转历史记录")
    @GetMapping(value = "queryZwxtLcljjl")
    public HttpResult queryZwxtLcljjl(@RequestParam(value = "sqsxid",defaultValue = "") String sqsxid){
        Map resultMap = new HashMap();

        /*if (StringUtils.isNotBlank(sqsxid)) {
            SpcySqsxBasic sqsx = spcySqsxBaiscService.selectCodeFxzspztAndById(sqsxid);
            if (sqsx != null) {
                sqsxid = sqsx.getFsxsqjbxxid();
            }
        }*/

        // 办理流程历史记录
        resultMap.putAll(this.lcLsJl(sqsxid));

        return HttpResult.ok(resultMap);
    }

    // 药品生产
    private Map sqsxFormInYpsc(String sqsxid,String sqsxbm,XzspSqsxVo sqsxObject){
        Map resultMap = new HashMap();

        // 变更医疗机构制剂许可证配制范围或配制地址的审批
        if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Ypsc_Sqsx_bm_001002005.getIndex())) {
            resultMap.putAll(ypscXzxkService.bgYlqxZjXkzPzFwHPzDzDsp(sqsxid, sqsxObject));

        }
        else if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Ypsc_Sqsx_bm_001002001.getIndex())) {
            // 变更《药品生产许可证》生产范围或生产地址审批
            resultMap.putAll(ypscXzxkService.bgYpscxkzScfwHScdzSp(sqsxid, sqsxObject));

        }
        else if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Ypsc_Sqsx_bm_001002035.getIndex())) {
            // 医疗机构委托配制中药制剂备案
            resultMap.putAll(ypscXzxkService.yljgWtPzZyZjBa(sqsxid, sqsxObject));

        }
        else if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Ypsc_Sqsx_bm_001002051.getIndex())) {
            // 药品生产质量管理规范符合性检查申请
            resultMap.putAll(ypscXzxkService.ypscZlGlGfFhxJcSq(sqsxid, sqsxObject));

        }
        else if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Ypsc_Sqsx_bm_001002003.getIndex())) {
            // 药品生产企业设立审批
            resultMap.putAll(ypscXzxkService.ypscQySlSp(sqsxid, sqsxObject));

        }
        else if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Ypsc_Sqsx_bm_001002028.getIndex())) {
            // 出口欧盟原料药证明文件审批
            resultMap.putAll(ypscXzxkService.ckomYlyZmwjSp(sqsxid));

        }
        else if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Ypsc_Sqsx_bm_001002026.getIndex())) {
            // 药品出口销售证明申请
            resultMap.putAll(ypscXzxkService.ypckXszmSq(sqsxid));

        }
        else if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Ypsc_Sqsx_bm_001002013.getIndex())) {
            // 放射性药品使用许可证核发（一、二类）
            resultMap.putAll(ypscXzxkService.fsxYpsyxkzHfOneAndTwo(sqsxid));

        }
        else if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Ypsc_Sqsx_bm_001002016.getIndex())) {
            // 放射性药品生产许可证审批
            resultMap.putAll(ypscXzxkService.fsxYpscxkzSp(sqsxid));

        }
        else if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Ypsc_Sqsx_bm_001002058.getIndex())) {
            // 放射性药品生产许可证变更
            resultMap.putAll(ypscXzxkService.fsxYpscxkzBg(sqsxid));

        }
        else {

            // 企业信息
            List<XzspSqsxXdrxxVo> qyList = xzXkMapper.selectQyxxList(sqsxid);

            if (CollectionUtils.isNotEmpty(qyList)) {
                resultMap.put("qyxx", qyList.get(0));
            } else {
                resultMap.put("qyxx", new JSONObject());
            }

            // 企业人员-主要人员 / 其他人员
            resultMap.putAll(ypscXzxkService.qyryListMap(sqsxid));
        }

        return resultMap;
    }

    // 药品流通
    private Map sqsxFormInYplt(String sqsxid,String sqsxbm){
        Map resultMap = new HashMap();

        // 药品批发经营企业设立审批
        if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Yplt_Sqsx_bm_001003002.getIndex())) {
            // 药品批发经营企业设立审批
            resultMap.putAll(ypltXzxkService.ypPfJyQySlSp(sqsxid));

        }
        else if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Yplt_Sqsx_bm_001003004.getIndex())) {
            // 药品经营批发企业药品经营许可证换发审批
            resultMap.putAll(ypltXzxkService.ypJypfQyYpJyXkzHfSp(sqsxid));

        }
        else if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Yplt_Sqsx_bm_001003006.getIndex())) {
            // 零售连锁总部药品经营许可证核发
            resultMap.putAll(ypltXzxkService.lsLsZbYpJyXkzHf(sqsxid));

        }
        else if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Yplt_Sqsx_bm_001003003.getIndex())){
            // 药品经营批发企业《药品经营许可证》事项变更审批
            resultMap.putAll(ypltXzxkService.ypjyPfqyYpjyXkzSxbgSp(sqsxid));

        }
        else if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Yplt_Sqsx_bm_001003039.getIndex())){
            // 药品批发企业药品现代物流企业确认件发放
            resultMap.putAll(ypltXzxkService.ypPfqyYpXdwlqyQrff(sqsxid));

        }
        else if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Yplt_Sqsx_bm_001003019.getIndex())){
            // 药品批发企业经营蛋白同化制剂、肽类激素审批
            resultMap.putAll(ypltXzxkService.yppfqyjytljssp(sqsxid));

        }
        else if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Yplt_Sqsx_bm_001003058.getIndex())){
            // 专门从事第二类精神药品批发企业经营审批
            resultMap.putAll(ypltXzxkService.zmcsDelJsypPfqyjySp(sqsxid));

        }
        else if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Yplt_Sqsx_bm_001003026.getIndex())){
            // 药品经营零售企业药品经营许可证换发审批
            resultMap.putAll(ypltXzxkService.ypjyLsqyYpjyXkzhfSp(sqsxid));

        }
        else if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Yplt_Sqsx_bm_001003008.getIndex())){
            // 零售连锁总部药品经营许可证换发
            resultMap.putAll(ypltXzxkService.lslszbYpjyXkzHf(sqsxid));

        }
        else if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Yplt_Sqsx_bm_001003025.getIndex())){
            // 药品经营（零售企业）设立验收审批
            resultMap.putAll(ypltXzxkService.ypjyLsqySlysSp(sqsxid));

        }
        else if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Yplt_Sqsx_bm_001003010.getIndex())){
            // 购买第一类中的药品类易制毒化学品审批
            resultMap.putAll(ypltXzxkService.gmDylzdYplYzdhxpSp(sqsxid));

        }else {

        }

        return resultMap;
    }

    // 药品注册
    private Map sqsxFormInYpzc(String sqsxid,String sqsxbm){
        Map resultMap = new HashMap();

        // 变更生产场地备案
        if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Ypzc_Sqsx_bm_001001027.getIndex())) {
            // 变更生产场地备案
            resultMap.putAll(ypzcXzxkService.bgSccdBa(sqsxid));

        }
        else if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Ypzc_Sqsx_bm_001001045.getIndex())){
            // 医疗机构制剂注册补充申请
            resultMap.putAll(ypzcXzxkService.yljgZjzcBcsq(sqsxid));

        }
        else if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Ypzc_Sqsx_bm_001001005.getIndex())){
            // 修改制剂注册标准
            resultMap.putAll(ypzcXzxkService.xgZjzcBz(sqsxid));

        }
        else {

        }

        return resultMap;
    }

    // 医疗器械
    private Map sqsxFormInYlqx(String sqsxid,String sqsxbm,XzspSqsxVo sqsxObject){
        Map resultMap = new HashMap();

        // 第二类体外诊断试剂注册证核发
        if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Ylqx_Sqsx_bm_002001004.getIndex())) {
            // 第二类体外诊断试剂注册证核发
            resultMap.putAll(ylqxXzxkService.delTwZdSjZczHf(sqsxid, sqsxObject));

        }
        else if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Ylqx_Sqsx_bm_002001006.getIndex())){
            // 第二类体外诊断试剂变更注册
            resultMap.putAll(ylqxXzxkService.delTwZdSjBgzc(sqsxid));

        }
        else if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Ylqx_Sqsx_bm_002001001.getIndex())) {
            // 第二类医疗器械注册证核发
            resultMap.putAll(ylqxXzxkService.delYlqxZczHf(sqsxid, sqsxObject));

        }
        else if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Ylqx_Sqsx_bm_002002001.getIndex())) {
            // 医疗器械（二类、三类）生产许可证核发
            resultMap.putAll(ylqxXzxkService.ylqxDeDslScxkzHf(sqsxid, sqsxObject));

        }
        else if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Ylqx_Sqsx_bm_002002003.getIndex())) {
            // 医疗器械（二类、三类）生产许可延续
            resultMap.putAll(ylqxXzxkService.ylqxDeDslScxkys(sqsxid, sqsxObject));

        }
        else if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Ylqx_Sqsx_bm_002001021.getIndex())) {
            // 医疗器械分类界定申请
            resultMap.putAll(ylqxXzxkService.ylqxFljdSq(sqsxid, sqsxObject));

        }
        else if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Ylqx_Sqsx_bm_002001002.getIndex())){
            // 第二类医疗器械变更注册
            resultMap.putAll(ylqxXzxkService.delYlqxBgZc(sqsxid, sqsxObject));

        }
        else if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Ylqx_Sqsx_bm_002001003.getIndex())){
            // 第二类医疗器械延续注册
            resultMap.putAll(ylqxXzxkService.delYlqxYxZc(sqsxid, sqsxObject));

        }
        else if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Ylqx_Sqsx_bm_002002002.getIndex())){
            // 医疗器械（二类、三类）生产许可变更
            resultMap.putAll(ylqxXzxkService.ylqxDeDslScxkBg(sqsxid, sqsxObject));

        }
        else {
            // 企业信息
            List<XzspSqsxXdrxxVo> qyList = xzXkMapper.selectQyxxList(sqsxid);
            if (CollectionUtils.isNotEmpty(qyList)) {
                resultMap.put("qyxx", qyList.get(0));
            } else {
                resultMap.put("qyxx", new JSONObject());
            }


        }

        return resultMap;
    }

    // 化妆品
    private Map sqsxFormInHzp(String sqsxid,String sqsxbm){
        Map resultMap = new HashMap();

        // 化妆品生产许可证核发
        if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Hzp_Sqsx_bm_003001.getIndex())) {
            // 化妆品生产许可证核发
            resultMap.putAll(hzpXzxkService.hzpScxkzHf(sqsxid));

        }
        else if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Hzp_Sqsx_bm_003007.getIndex())) {
            // 化妆品生产许可证注销
            resultMap.putAll(hzpXzxkService.hzpScxkzZx(sqsxid));

        }
        else if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Hzp_Sqsx_bm_003004.getIndex())) {
            // 化妆品生产许可证许可事项变更
            resultMap.putAll(hzpXzxkService.hzpScxkzXksxBg(sqsxid));

        }
        else if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Hzp_Sqsx_bm_003009.getIndex())) {
            // 国产非特殊用途化妆品备案
            resultMap.putAll(hzpXzxkService.gcFtsytHzpBa(sqsxid));

        }
        else if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Hzp_Sqsx_bm_003003.getIndex())) {
            // 化妆品生产许可证登记事项变更
            resultMap.putAll(hzpXzxkService.hzpScxkzDjsxBg(sqsxid));

        }
        else if (StringUtils.isNotBlank(sqsxbm) && sqsxbm.equals(XzXkEnumConstant.Hzp_Sqsx_bm_003005.getIndex())) {
            // 化妆品生产许可报告事项变更
            resultMap.putAll(hzpXzxkService.hzpScxkBgsxBg(sqsxid));

        }

        return resultMap;
    }

    @Log(title = "获取申请事项名称-编码")
    @ApiOperation(value = "获取申请事项名称-编码")
    @GetMapping(value = "getSqsxBm")
    public HttpResult<?> getSqsxBm(@RequestParam(value = "sqsxid",defaultValue = "OAOCSS") String sqsxid){
        String sqsxbm = "";

        /*SpcySqsxBasic sqsx = spcySqsxBaiscService.selectSqsxYwflCodeById(sqsxid);

        if (sqsx == null){

            HttpResult result = new HttpResult(true);
            result.setResult(sqsxbm);
            result.setMessage("操作成功");
            return result;

        }else {
            sqsxid = sqsx.getFsxsqjbxxid();
        }

        // 申请事项
        XzspSqsxVo sqsxMap = xzXkMapper.selectSqsxBm(sqsxid);

        if (sqsxMap == null){
            HttpResult result = new HttpResult(true);
            result.setResult(sqsxbm);
            result.setMessage("操作成功");
            return result;

        }else {
            sqsxbm = sqsxMap.getSqsxbm();
        }*/

        HttpResult result = new HttpResult(true);
        result.setResult(sqsxbm);
        result.setMessage("操作成功");
        return result;
    }

    @Log(title = "经营范围 - 数据字典")
    @ApiOperation(value = "经营范围 - 数据字典")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "fywflcode", value = "业务分类编码"),
            @ApiImplicitParam(name = "jdbm", value = "字典编码"),
    })
    @GetMapping(value = "queryZdglByJyfw")
    public HttpResult<?> queryZdglByJyfw(@RequestParam(value = "fywflcode",defaultValue = "") String fywflcode,
                                         @RequestParam(value = "jdbm",defaultValue = "") String jdbm){
        /*if (StringUtils.isBlank(fywflcode)) {
            return HttpResult.error("业务编码不能为空");
        }*/

        /**
         * 药品生产（项目范围）ypsc_xmfw
         *  事项分类 sxfl
         *  医疗器械经营范围  ylqxjyfw
         *  化妆品生产许可项目 hzpscxkxm
         *  药品流通经营范围 ypltjyfw
         *  药品流通经营范围（现代物流确认件） ypltjyfw_xdwlqrj
         *  企业类别编码(证件类别) qylbbm
         *
         *  化妆品生产产品单元   hzpsccpdy
         *  医疗器械生产第一类范围 ylqxscdylfw
         *  医疗器械生产第二类范围 ylqxscdelfw
         *  医疗器械生产第三类范围 ylqxscdslfw
         *  医疗器械生产第二、三类范围    ylqxscdeslfw
         *  结果公示分类  jggsfl
         */
        String nowJdbm = "";

        /*if (StringUtils.isBlank(jdbm)) {
            if (fywflcode.equals(SpcyConstant.YWFL_CODE_YPSC)) {
                // 药品生产
                nowJdbm = "ypsc_xmfw";

            } else if (fywflcode.equals(SpcyConstant.YWFL_CODE_YPJY)) {
                // 药品流通
                nowJdbm = "ypltjyfw";

            } else if (fywflcode.equals(SpcyConstant.YWFL_CODE_YLQX)) {
                // 医疗器械
                nowJdbm = "ylqxjyfw";
            } else {

            }
        }else {
            nowJdbm = jdbm;
        }

        List<Map<String, Object>> zdglList = xzXkMapper.zdglTree(nowJdbm);*/

        return HttpResult.ok(new ArrayList<>(1));
    }

    @Log(title = "查询业务字段-通过业务编码查询")
    @ApiOperation(value = "查询业务字段-通过业务编码查询")
    @GetMapping(value = "queryYwzdByCode")
    public HttpResult<?> queryYwzdByCode(@RequestParam(value = "zdbm",defaultValue = "OAOCSS")String zdbm){
//        List<Map<String, Object>> zdList = xzXkMapper.ywzdWithZdmcOrZdbm(null, zdbm, null);

        return HttpResult.ok();
    }

    @Log(title = "查询企业人员类型字典")
    @ApiOperation(value = "查询企业人员类型字典")
    @GetMapping(value = "queryQyrylxList")
    public HttpResult<?> queryQyrylxList(){
//        List<Map<String, Object>> zdList = xzXkMapper.ywzdWithZdmcOrZdbm(null, XzXkEnumConstant.Zdgl_ywzd_Rylx.getIndex(), null);

        return HttpResult.ok();
    }

    @Log(title = "查看-申请材料")
    @ApiOperation(value = "查看-申请材料")
    @GetMapping(value = "downloadXzxkFjxx")
    public void downloadXzxkFjxx(String id,
                                 @RequestParam(value = "symc",defaultValue = "") String symc,
                                 HttpServletResponse response) {
        return;
        /*List<Map<String, Object>> fjList = xzXkMapper.selectFjxxById(id);
        if (CollectionUtils.isNotEmpty(fjList)){
            String fjbclj = fjList.get(0).get(XzXkConstant.ZD_FJXX_FJBCLJ).toString();
            if (StringUtils.isBlank(fjbclj)){
                throw new BusinessException("当前附件记录，文件不存在！");
            }
//            spcyMinioUtils.downLoadXzspFile(fjbclj,response);
            this.downLoadXzspFileSy(fjbclj, symc, response);
        }else {
            throw new BusinessException("当前附件记录不存在！");
        }*/
    }

    @Log(title = "下载-申请材料")
    @ApiOperation(value = "下载-申请材料")
    @GetMapping(value = "downloadXzxkFjxxSy")
    public void downloadXzxkFjxxSy(String id, HttpServletResponse response) {
        return;

        /*List<Map<String, Object>> fjList = xzXkMapper.selectFjxxById(id);
        if (CollectionUtils.isNotEmpty(fjList)){
            String fjbclj = fjList.get(0).get(XzXkConstant.ZD_FJXX_FJBCLJ).toString();
            if (StringUtils.isBlank(fjbclj)){
                throw new BusinessException("当前附件记录，文件不存在！");
            }
            String symc = GetCurrentUserUtils.getCurrentUserName() + DateConversionUtils.DateToString(new Date());
            this.downLoadXzspFileSy(fjbclj, symc, response);
        }else {
            throw new BusinessException("当前附件记录不存在！");
        }*/
    }

    /** 水印下载 */
    private void downLoadXzspFileSy(String fjbclj, String symc, HttpServletResponse response){
        String wjhz = Util.getWjHz(fjbclj);
        if (wjhz.equals(".doc") || wjhz.equals(".docx") || wjhz.equals(".pdf")) {

            if (StringUtils.isBlank(symc)){
                spcyMinioUtils.downLoadXzspFile(fjbclj,response);
            }else {
                InputStream minioInput = spcyMinioUtils.getXzspFileObject(fjbclj);
                if (minioInput == null){
                    throw new BusinessException("文件流不存在！");
                }
                File file = localFileUploadUtils.asFile(minioInput, wjhz);

                localFileUploadUtils.ejzLocalFileSy(file.getAbsolutePath(), wjhz, symc, response);
            }
        }else {
            spcyMinioUtils.downLoadXzspFile(fjbclj, response);
        }
    }

    @PostMapping(value = "zdyLoad")
    public void zdyLoad(@RequestBody Map<String, String> parMap, HttpServletResponse response){

        String url = "";
        String flag = "0";
        try {
            url = parMap.get("url");
            flag = parMap.get("flag");
        }catch (Exception e){

        }

        log.info("orgUrl: {}", url);
        if (flag.equals("1")) {
            url = spcyMinioUtils.XzspFileUrl(url);
        }
        log.info("outUrl: {}", url);

        spcyMinioUtils.zdyDownXzspFile(url, response);
    }

    @Log(title = "下载文件压缩包-申请材料")
    @ApiOperation(value = "下载文件压缩包-申请材料")
    @ApiImplicitParam(name = "sqsxid",value = "申请事项id",required = true)
    @GetMapping(value = "downloadZipFile")
    public void downloadZipFile(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid,HttpServletResponse response) throws IOException {
        if (org.apache.commons.lang3.StringUtils.isBlank(sqsxid)){
            response.setContentType("text/html");
            response.setCharacterEncoding("UTF-8");
            PrintWriter writer = response.getWriter();
            writer.println("参数为空！");
            writer.close(); // 不要忘记关闭PrintWriter

            return;
        }

        SpcySqsxBasic sqsx = spcySqsxBaiscService.selectSqsxById(sqsxid);
        if (sqsx == null){
            response.setContentType("text/html");
            response.setCharacterEncoding("UTF-8");
            PrintWriter writer = response.getWriter();
            writer.println("没有相匹配的数据！");
            writer.close(); // 不要忘记关闭PrintWriter

            return;
        }else {
            sqsxid = sqsx.getFsxsqjbxxid();
        }

        List<InputStream> files = new ArrayList<>();
        List<String> fileNames = new ArrayList<>();
        /*List<Map<String, Object>> fjxxList = xzXkMapper.selectFjxx(sqsxid, "0");
        if (CollectionUtils.isNotEmpty(fjxxList)){
            for (Map<String, Object> wjjl : fjxxList){
                String fjbclj = wjjl.get(XzXkConstant.ZD_FJXX_FJBCLJ).toString();
                if (org.apache.commons.lang3.StringUtils.isNotBlank(fjbclj)) {
                    InputStream xzspFileObject = spcyMinioUtils.getXzspFileObject(fjbclj);
                    if (xzspFileObject != null) {
                        fileNames.add(wjjl.get(XzXkConstant.ZD_FJXX_FJYMC).toString());
                        files.add(xzspFileObject);
                    }
                }
            }
        }*/

        PdfUtils.downInputZip(files, fileNames, response);
    }

    @Log(title = "查询企业-补齐补正材料")
    @ApiOperation(value = "查询企业-补齐补正材料")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "sqsxid",value = "申请事项id"),
            @ApiImplicitParam(name = "isSelectSlsj",value = "是否查询受理时间之后的补齐补正材料，默认：false/true")
    })
    @GetMapping(value = "queryBqbzFileList")
    public HttpResult<?> queryBqbzFileList(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("申请事项参数为空");
        }

        Map resultMap = new HashMap();

        /*SpcySqsxBasic sqsx = spcySqsxBaiscService.getById(sqsxid);
        if (sqsx == null){
            resultMap.put("qybqbzList", new ArrayList<>());
            return HttpResult.ok();
        }else {
            sqsxid = sqsx.getFsxsqjbxxid();
        }
        String zdrq = "";
        if (StringUtils.isBlank(zdrq) && sqsx.getFslsj() != null){
            zdrq = DateConversionUtils.DateToDays(sqsx.getFslsj());
        }else {
            zdrq = DateConversionUtils.DateToDays(new Date());
        }

        List<Map<String, Object>> fjxxList = xzXkMapper.selectFjxxSqsjWithDySlsj(sqsxid, XzXkConstant.FJXX_FJLX_QYTJCL,XzXkConstant.FJXX_FJBZ_BQBZ,zdrq,null);
        JSONArray fjxxArray = MapUtils.listMapToJson(fjxxList);*/
        resultMap.put("qybqbzList", new JSONArray());

        return HttpResult.ok(resultMap);
    }

    @Log(title = "提取业务部门经办人")
    @ApiOperation(value = "提取业务部门经办人")
    @GetMapping(value = "queryYwbmjbrList")
    public HttpResult queryYwbmjbrList(@RequestParam(value = "sqsxid",defaultValue = "") String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("申请事项参数为空");
        }
        /*SpcySqsxBasic sqsx = spcySqsxBaiscService.getById(sqsxid);
        if (sqsx == null){
            return HttpResult.ok();
        }
        else {
            sqsxid = sqsx.getFsxsqjbxxid();
        }*/
        List<BusinessDept> businessDepts = new ArrayList<>();
        if (verifyEnableSyncSqsx()) {
            businessDepts = xzspJkApi.tqYwbmjbr(sqsxid);

        }else {

            BusinessDept dept = new BusinessDept();
            dept.setId("zwfwxtysrid");
            dept.setDeptId("zwfwxtysrDeptId");
            dept.setDeptName("办公室");
            dept.setName("行政审批账号");
            businessDepts.add(dept);
        }

        return HttpResult.ok(businessDepts);
    }

    @Log(title = "保存业务部门经办人")
    @ApiOperation(value = "保存业务部门经办人")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "sqsxid",value = "申请事项id"),
            @ApiImplicitParam(name = "jbrid",value = "经办人id")
    })
    @GetMapping(value = "saveYwbmjbr")
    public HttpResult saveYwbmjbr(@RequestParam(value = "sqsxid",defaultValue = "") String sqsxid,
                                  @RequestParam(value = "jbrid",defaultValue = "")String jbrid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("申请事项参数为空");
        }

        if (StringUtils.isBlank(jbrid)){
            return HttpResult.error("经办人参数为空");
        }

        if (verifyEnableSyncSqsx()) {
            xzspJkApi.updateSqsxYwbmjbr(sqsxid, jbrid);

        }else {
            BusinessDept dept = new BusinessDept();
            dept.setId("zwfwxtysrid");
            dept.setDeptId("zwfwxtysrDeptId");
            dept.setDeptName("办公室");
            dept.setName("行政审批账号");
            spcySqsxBaiscService.updateSqsxYwbmjbr(sqsxid, dept);
        }

        return HttpResult.ok("保存成功");
    }

    /*@Log(title = "根据指定日期-查询企业-补齐补正材料")
    @ApiOperation(value = "根据指定日期-查询企业-补齐补正材料")
    @GetMapping(value = "queryBqbzFileListWithZdrq")
    public HttpResult<?> queryBqbzFileListWithZdrq(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid,
                                                   @RequestParam(value = "zdrq",defaultValue = "")String zdrq){
        Map resultMap = new HashMap();

        SpcySqsxBasic sqsx = spcySqsxBaiscService.getById(sqsxid);
        if (sqsx == null){
            return HttpResult.ok();
        }else {
            sqsxid = sqsx.getFsxsqjbxxid();
        }

        if (StringUtils.isBlank(zdrq) && sqsx.getFslsj() != null){
            zdrq = DateConversionUtils.DateToDays(sqsx.getFslsj());
        }

        List<Map<String, Object>> fjxxList = xzXkMapper.selectFjxxSqsjWithDySlsj(sqsxid, XzXkConstant.FJXX_FJLX_QYTJCL,XzXkConstant.FJXX_FJBZ_BQBZ,zdrq);
        JSONArray fjxxArray = MapUtils.listMapToJson(fjxxList);
        resultMap.put("qybqbzList", fjxxArray);

        return HttpResult.ok(resultMap);
    }*/

    @Log(title = "查询企业-企业整改材料")
    @ApiOperation(value = "查询企业-企业整改材料")
    @GetMapping(value = "queryZgclFileList")
    public HttpResult<?> queryZgclFileList(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        Map resultMap = new HashMap();

        /*SpcySqsxBasic sqsx = spcySqsxBaiscService.getById(sqsxid);
        if (sqsx == null){
            resultMap.put("qyzgclList", new ArrayList<>());
            return HttpResult.ok(resultMap);
        }else {
            sqsxid = sqsx.getFsxsqjbxxid();
        }

        List<Map<String, Object>> fjxxList = xzXkMapper.selectFjxxBybqbz(sqsxid, XzXkConstant.FJXX_FJLX_QYZGCL,null);
        JSONArray fjxxArray = MapUtils.listMapToJson(fjxxList);*/
        resultMap.put("qyzgclList", new JSONArray());

        return HttpResult.ok(resultMap);
    }

    @Log(title = "查询企业-企业撤件申请材料")
    @ApiOperation(value = "查询企业-企业撤件申请材料")
    @GetMapping(value = "queryQycjsqFileList")
    public HttpResult<?> queryQycjsqFileList(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        Map resultMap = new HashMap();

        /*SpcySqsxBasic sqsx = spcySqsxBaiscService.getById(sqsxid);
        if (sqsx == null){
            resultMap.put("qycjsqclList", new ArrayList<>());
            return HttpResult.ok(resultMap);
        }else {
            sqsxid = sqsx.getFsxsqjbxxid();
        }

        List<Map<String, Object>> fjxxList = xzXkMapper.selectFjxxBybqbz(sqsxid, XzXkConstant.FJXX_FJLX_QYTJCL,null);
        JSONArray fjxxArray = MapUtils.listMapToJson(fjxxList);*/
        resultMap.put("qycjsqclList", new JSONArray());

        return HttpResult.ok(resultMap);
    }

    /**
     * 流程历史记录
     * @param sqsxid
     * @return
     */
    private Map lcLsJl(String sqsxid){
        Map resultMap = new HashMap();

//        List<XzspLcLsjlVo> lcLsJlList = xzXkMapper.lcLsJl(sqsxid);
        resultMap.put("lclsjlList", new JSONArray());

        return resultMap;
    }
}
